<?php

declare(strict_types=1);

namespace App\Command;

use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Psr\Container\ContainerInterface;

use App\Query\ConfigQuery;
use App\Query\OrderQuery;
use App\Query\UserQuery;
use App\Repository\UserRepository;
use App\Job\OrderMoneyRemainJob;

/**
 * @Command
 */
class Test extends HyperfCommand
{
    public function __construct()
    {
        parent::__construct('test');
    }
    
    public function handle()
    {
        // 获取用户
        $user = UserRepository::find(2);
        
        // 配置
        $config = ConfigQuery::get();
        
        $repository = UserRepository::make();
        
        // 寻找未锁定的用户并且有等级的
        $users = UserQuery::moneyRemainTime(UserQuery::lockNo(
            UserQuery::level(UserQuery::model(), 1)
        ))->get();
        
        // 循环检查的用户
        foreach($users as $user)
        {
            // 获取用户是否还有可释放的订单
            if(!OrderQuery::remain(OrderQuery::user($user))->count())
            {
                // 如果没有，那就冻结帐号
                $repository->model($user);
                
                // 冻结
                $repository->setLockStatus();
            }
        }
    }
}
